package fiuba.td.fabrica.main;

import java.util.Random;

public class TestMain {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		int vec[][] = new int[3][3];
		Random random = new Random (1);
		for ( int i=0; i < 3; i++ ) {
	      for ( int j=0; j < vec[i].length; j++ ) {
	    	vec[i][j] = 5;
	        System.out.print( vec[i][j] +" " );
	      }
	      System.out.println();
	    }
		  System.out.println();
		dijkstra(vec);

	}

	public static void dijkstra( int graph[][] ){
        int d[] = new int[ graph.length ];
        int dC[] = new int[ graph.length ];
        int p[] = new int[ graph.length ];
        for( int i = 0; i < graph.length; i++ ){ d[ i ] = 100; dC[ i ] = 100; p[ i ] = -1; }
        d[ 0 ] = 0; dC[ 0 ] = 0;

        int i = 0, min = 200, pos = 0; //You can change the min to 1000 to make it the largest number
        while( i < graph.length ){
                //extract minimum
                for( int j = 0; j < dC.length; j++ ){
                        if( min > d[ j ] && dC[ j ] != -1 ){
                                min = d[ j ]; pos = j;
                        }
                }
                dC[ pos ] = -1;

                //relax
                for( int j = 0; j < graph.length; j++ ){
                        if( d[ j ] > graph[ pos ][ j ] + d[ pos ] ){
                                d[ j ] = graph[ pos ][ j ] + d[ pos ];
                                p[ j ] = pos;
                        }
                }
                i++; min = 200;
        }



        for( int j = 0; j < p.length; j++ ){
                System.out.print( p[ j ] + " " );
        }
        System.out.print( "\n" );
        for( int j = 0; j < d.length; j++ ){
                System.out.print( d[ j ] + " " );
        }
        System.out.print( "\n" );
}
}
